﻿
Partial Class App_Dashboard
    Inherits MyUI.PageBaseApp

    Public CurrAccount As mDB.Account
    Public CurrGroup As mDB.Group_Account
    Public FromDate, ToDate As Date
    'Public IntervalChart As Integer

    Private Excel As Export.Excel.ExcelXml

    Protected WithEvents GroupConsoleDay As UI.GroupButton(Of LinkButton)
    Protected WithEvents GroupConsoleGroup As UI.GroupButton(Of LinkButton)

    Protected WithEvents PostWrite As App_Controls_PostWrite
    Protected WithEvents PrivateMessage As App_Controls_PrivateMessage


    'Public Property ReportDay() As String
    '    Get
    '        Return ViewState("report_day")
    '    End Get
    '    Set(ByVal value As String)
    '        ViewState("report_day") = value
    '    End Set
    'End Property

    'Public Property ReportGroup() As String
    '    Get
    '        Return ViewState("report_group")
    '    End Get
    '    Set(ByVal value As String)
    '        ViewState("report_group") = value
    '    End Set
    'End Property

#Region "PAGE"

    <Services.WebMethod()> _
    Public Shared Function get_geo_data(ByVal key As String) As Object
        Dim db = mDB.GetDB

        Dim CurrAccount = MyApp.GetUser.CurrAccount
        Dim DataChart As New List(Of Object())
        Dim dt As DataTable
        Dim TotalMap As Integer = 0

        Dim region = key
        Dim displayMode = "markers"

        dt = CurrAccount._Tab_Account_Link(mDB._Account_Link.Type.FOLLOWER).
            REL._Account_Link.Account.
            REL.Account.Account_Add_Info.
            REL.Account_Add_Info.Place.
            Where("country_code", "=", key).
            GroupBy("concat(locality,city,county, state,country)").
            SetSelect("place.name", "count(place.id) as value", "lon", "lat", "locality", "city", "county", "state", "country", "place_type").
        ToDataTable()


        DataChart.Add({"lat", "lng", "name", "value"})

        For Each dr As DataRow In dt.Rows

            TotalMap += dr("value")

            Dim Lng = dr("Lon")
            Dim Lat = dr("Lat")
            Dim Name = ""

            If dr("locality") <> "" Then
                Name &= dr("locality") & ", "
            End If
            If dr("city") <> "" Then
                Name &= dr("city") & ", "
            End If
            If dr("county") <> "" Then
                Name &= dr("county") & ", "
            End If
            If dr("state") <> "" Then
                Name &= dr("state")
            End If

            If Name = "" Then
                Name = dr("country")
            End If

            DataChart.Add({Lat, Lng, Name, dr("value")})
        Next


        'Dim json = MyApp.JSONSerialize(New With {
        '    .data = DataChart,
        '    .region = region,
        '    .displayMode = displayMode, .total = TotalMap
        '})

        Dim json = New With {
            .data = DataChart,
            .region = region,
            .displayMode = displayMode, .total = TotalMap
        }

        Return json

    End Function



    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load


        ScriptManager.GetCurrent(Page).EnablePageMethods = True

        Me.GroupConsoleDay = New UI.GroupButton(Of LinkButton)(Me.ViewState, "CONSOLE_DAY", "pg-count-h")
        Me.GroupConsoleGroup = New UI.GroupButton(Of LinkButton)(Me.ViewState, "CONSOLE_GROUP", "pg-count-h")
        Me.PostWrite = FC("PostWrite", Master)
        Me.PrivateMessage = FC("PrivateMessage", Master)

        Me.CurrAccount = CurrUser.CurrAccount
        Me.CurrGroup = CurrUser.CurrGroup

        If Not Me.IsPostBack Then
            'Me.ReportDay = 30
            Me.GroupConsoleDay.SelectButton = RbtDay30
            Me.GroupConsoleGroup.SelectButton = RbtDaily
            'Me.ReportGroup = "d"
            SetDataPage()
        Else
            'SetCurrAccount()
        End If


    End Sub
    Private Sub SetDataPage()


        Me.SetDataAnalysis()


    End Sub

#End Region



#Region "SET DATA"

    Private Sub SetDataAnalysis()

        If CurrAccount IsNot Nothing Then

            Me.UpPCharMap.Visible = MyApp.DataNet(CurrAccount.Network_Id).Available.AccountGeoLocate

            Me.SetDataConsole()

            Me.SetDataLocation()
            Me.SetDataFollower()
            Me.SetDataPostSent()
            Me.SetDataMessShare()
            Me.SetDataStatus()
            Me.SetDataEngagImpress()
            Me.SetDataAutoFollow()
            Me.SetDataActivity()

            Me.SetListInterractionAccount()
            Me.SetListSharePost()
            Me.SetListNewFollowerAccount()

            Me.SetDataLanguage()
            Me.SetDataGender()

        End If

    End Sub
    Private Sub SetDataLocation()


        'Dim dtold = CurrAccount.
        '    Tab_Follower_Analysis(mDB.Follower_Analysis.Type.PLACE).
        '    Join("place_country", "id", "Follower_Analysis.data_type_id").
        '    SetSelect("place_country.country_code", "short_name", "Follower_Analysis.value").
        '    OrderBy("value desc").
        'ToDataTable

        Dim fas = CurrGroup.GetFollowerAnalysis(GloukDB.Follower_Analysis.Type.PLACE)
        If fas.Count > 0 Then

            Dim country = DB.TAB.Place_Country.Where("id", "in", fas.Select(Function(o) o.Data_Type_Id).ToList).ToList
            Dim dt =
                From fa In fas
                Join c In country On fa.Data_Type_Id Equals c.Id
                Select c.Country_Code, c.Short_Name, fa.Value
                Order By Value Descending


            'excel
            If Excel IsNot Nothing Then
                Dim SheetFoll = Excel.GetExcelXmlSheet(2)
                SheetFoll.PasteData(2, "J", dt, "short_name", "value")
            End If


            'char
            Dim DataChart As New List(Of Object())
            DataChart.Add({"country_code", "short_name", "value"})
            For ct = 0 To dt.Count - 1
                DataChart.Add({dt(ct).Country_Code, dt(ct).Short_Name, dt(ct).Value})
            Next

            Dim TotalMap = (From r In dt).Sum(Function(o) o.Value)
            Dim region = "world"
            Dim displayMode = "regions"


            Dim json = MyApp.JSONSerialize(New With {
                .data = DataChart,
                .region = region,
                .displayMode = displayMode,
                .total = TotalMap
            })

            Me.AddJScript(SF("DrawChartLocation({0});", json))
        End If


    End Sub
    Protected Sub LnkResetMap_Click(sender As Object, e As EventArgs) Handles LnkResetMap.Click
        SetDataLocation()

    End Sub


    Private Sub SetDataPostSent()

        Dim t1 = CreateQueryTrend(mDB._Trend.Type.POST_REL)

        Me.LblPostCount.Text = UI.Print.Num0(t1.Sum(Function(o) o.Value))
        Me.LblPostAvg.Text = UI.Print.Num1(Utils.Math.Div(t1.Sum(Function(o) o.Value), t1.Count))

        '-------------------------------------
        ' EXCEL

        If Excel IsNot Nothing Then
            Dim SheetTrend = Excel.GetExcelXmlSheet(3)
            SheetTrend.PasteData(3, "C", t1, {"value"})
        End If

        '-------------------------------------
        ' CHART

        Dim DataChart As New List(Of Object())
        DataChart.Add({"data", "Sent post"})
        For ct = 0 To t1.Count - 1
            DataChart.Add({MyUI.Print.DateMonthDay(t1(ct).Trend_Date), t1(ct).Value})
        Next

        Dim json = MyApp.JSONSerialize(New With {
            .data = DataChart
        })

        Me.AddJScript(SF("DrawChartPostSend({0});", json))


    End Sub
    Private Sub SetDataFollower()

        Dim t1 = CreateQueryTrend(mDB._Trend.Type.FOLLOWER_ABS)
        Dim t2 = CreateQueryTrend(mDB._Trend.Type.FOLLOWER_REL)
        Dim t3 = CreateQueryTrend(mDB._Trend.Type.UNFOLLOWER_REL)

        If t1.Count > 0 Then
            Me.LblFollowersCount.Text = UI.Print.Num0S(t1(t1.Count - 1).Value - t1(0).Value)
            Me.LblFollowersAvg.Text = UI.Print.Num1S(Utils.Math.Div(t1(t1.Count - 1).Value - t1(0).Value, t1.Count))
        Else
            Me.LblFollowersCount.Text = UI.Print.Num0S(0)
            Me.LblFollowersAvg.Text = UI.Print.Num1S(0)

        End If

        '-------------------------------------
        ' EXCEL

        If Excel IsNot Nothing Then
            Dim SheetData = Excel.GetExcelXmlSheet(3)
            SheetData.PasteData(3, "B", t1, {"value"})
        End If

        '-------------------------------------
        ' CHART

        Dim DataChart As New List(Of Object())
        DataChart.Add({"data", "Followers", "Foll_day"})
        ripempii(Of mDB._Trend, Date)(t1, t2, Function(o) o.Trend_Date, Function(o) New mDB._Trend With {.Trend_Date = o, .Value = 0})
        ripempii(Of mDB._Trend, Date)(t2, t1, Function(o) o.Trend_Date, Function(o) New mDB._Trend With {.Trend_Date = o, .Value = 0})
        ripempii(Of mDB._Trend, Date)(t2, t3, Function(o) o.Trend_Date, Function(o) New mDB._Trend With {.Trend_Date = o, .Value = 0})
        For ct = 0 To t1.Count - 1
            DataChart.Add({MyUI.Print.DateMonthDay(t1(ct).Trend_Date), t1(ct).Value, t2(ct).Value - t3(ct).Value})
        Next

        Dim json = MyApp.JSONSerialize(New With {
            .data = DataChart
        })

        Me.AddJScript(SF("DrawChartFollower({0});", json))


    End Sub

    'Sub ripempi(source As List(Of mDB._Trend), dest As List(Of mDB._Trend))

    '    Dim destdic = source.ToDictionary(Of Date)(Function(o) o.Trend_Date)

    '    For Each s In source
    '        If Not destdic.ContainsKey(s.Trend_Date) Then
    '            dest.Add(New mDB._Trend With {.Trend_Date = s.Trend_Date, .Value = 0})
    '        End If
    '    Next
    '    dest = dest.OrderBy(Function(o) o.Trend_Date)

    'End Sub
    Sub ripempii(Of tres As {New}, tkey)(ByRef source As List(Of tres), ByRef dest As List(Of tres), f As Func(Of tres, tkey), fnew As Func(Of tkey, tres))

        Dim destdic = dest.ToDictionary(Of tkey)(f)

        For Each s In source
            If Not destdic.ContainsKey(f(s)) Then
                dest.Add(fnew(f(s)))
            End If
        Next
        dest = dest.OrderBy(f).ToList

    End Sub

    Function outerjoin(Of tres)(l() As List(Of tres), f As Func(Of tres, Date)) As Dictionary(Of Date, List(Of tres))

        Dim res = New Dictionary(Of Date, List(Of tres))

        For ct = 0 To l.Length - 1

        Next

        res = res.OrderBy(Function(o) o.Key)


    End Function

    Private Sub SetDataMessShare()

        Dim t1 = CreateQueryTrend(mDB._Trend.Type.MESSAGE_REL)
        Dim t2 = CreateQueryTrend(mDB._Trend.Type.SHARE_REL)
        Dim t3 = CreateQueryTrend(mDB._Trend.Type.REPLY_REL)

        Me.LblMessageCount.Text = UI.Print.Num0(t1.Sum(Function(o) o.Value))
        Me.LblShareCount.Text = UI.Print.Num0(t2.Sum(Function(o) o.Value))

        Me.UpPChar2.Update()


        '-------------------------------------------------
        ' EXCEL

        If Excel IsNot Nothing Then
            Dim SheetTrend = Excel.GetExcelXmlSheet(3)
            SheetTrend.PasteData(3, "A", t1, {"trend_date"})
            SheetTrend.PasteData(3, "E", t1, {"value"})
            SheetTrend.PasteData(3, "F", t2, {"value"})
        End If

        '-------------------------------------------------
        'CHAR

        Dim DataChart As New List(Of Object())
        'DataChart.Add({"data", "Mention", "Retweet", "Reply"})
        DataChart.Add({"data", "Reply", "Mention", "Retweet"})
        For ct = 0 To t1.Count - 1 'Step' Each d In qt1.ToList

            Dim ShareVal = 0
            If ct < t2.Count Then
                ShareVal = t2(ct).Value
            End If
            Dim replyVal = 0
            If ct < t3.Count Then
                replyVal = t3(ct).Value
            End If

            DataChart.Add({MyUI.Print.DateMonthDay(t1(ct).Trend_Date), replyVal, t1(ct).Value - replyVal, ShareVal})
        Next

        Dim json = MyApp.JSONSerialize(New With {
            .data = DataChart
        })

        Me.AddJScript(SF("DrawChartMessShare({0});", json))



    End Sub

    Private Sub SetDataStatus()

        If Not CurrAccount.Account_Auth.Analysis_Followers Then

            Me.AddJScript(SF("div_upgrade_plain('#{0}');", Me.UpPStatus.ClientID))

        Else
            Dim t1 = CreateQueryTrend(mDB._Trend.Type.STATUS_FAKE)
            Dim t2 = CreateQueryTrend(mDB._Trend.Type.STATUS_INACTIVE)
            Dim t3 = CreateQueryTrend(mDB._Trend.Type.STATUS_LOW_ACTIVITY)
            Dim t4 = CreateQueryTrend(mDB._Trend.Type.STATUS_MEDIUM_ACTIVITY)
            Dim t5 = CreateQueryTrend(mDB._Trend.Type.STATUS_HIGHT_ACTIVITY)


            'Dim fa = CurrAccount.Tab_Follower_Analysis(mDB.Follower_Analysis.Type.STATUS).ToDictionary(Of mDB.Account.StatusType)("data_type_id")
            Dim fa = CurrGroup.GetFollowerAnalysis(mDB.Follower_Analysis.Type.STATUS).ToDictionary(Of mDB.Account.StatusType)(Function(o) o.Data_Type_Id)
            Dim TotStatus = fa.Sum(Function(o) o.Value.Value)

            'Dim TotMales = CurrAccount.GetFollowerAnalysis(mDB.Follower_Analysis.Type.STATUS, mDB.Account.StatusType.FAKE)
            'Dim TotFemales = CurrAccount.GetFollowerAnalysis(mDB.Follower_Analysis.Type.GENDER, mDB.Gender_Name.Type.FEMALE)

            If fa.Count >= 5 Then
                Me.LblStatusFake.Text = UI.Print.Num0(Utils.Math.Perc(fa(mDB.Account.StatusType.FAKE).Value, TotStatus)) & "%"
                Me.LblStatusInactive.Text = UI.Print.Num0(Utils.Math.Perc(fa(mDB.Account.StatusType.INACTIVE).Value, TotStatus)) & "%"

                Me.LblStatusHigh.Text = UI.Print.Num0(Utils.Math.Perc(fa(mDB.Account.StatusType.HIGHT_ACTIVITY).Value, TotStatus)) & "%"
                Me.LblStatusMedium.Text = UI.Print.Num0(Utils.Math.Perc(fa(mDB.Account.StatusType.MEDIUM_ACTIVITY).Value, TotStatus)) & "%"
                Me.LblStatusLow.Text = UI.Print.Num0(Utils.Math.Perc(fa(mDB.Account.StatusType.LOW_ACTIVITY).Value, TotStatus)) & "%"

                Me.LblStatusGood.Text = UI.Print.Num0(
                    Utils.Math.Perc(
                        fa(mDB.Account.StatusType.LOW_ACTIVITY).Value +
                        fa(mDB.Account.StatusType.MEDIUM_ACTIVITY).Value +
                        fa(mDB.Account.StatusType.HIGHT_ACTIVITY).Value,
                        TotStatus
                    )
                ) & "%"
            End If

            Me.UpPChar2.Update()


            '-------------------------------------------------
            ' EXCEL

            If Excel IsNot Nothing Then
                'Dim SheetTrend = Excel.GetExcelXmlSheet(3)
                'SheetTrend.PasteData(3, "A", qt1.ToDataTable, {"trend_date"})
                'SheetTrend.PasteData(3, "E", qt1.ToDataTable, {"value"})
                'SheetTrend.PasteData(3, "F", qt2.ToDataTable, {"value"})
            End If

            '-------------------------------------------------
            'CHAR

            Dim DataChart As New List(Of Object())
            DataChart.Add({"data", "Fake", "Inactive", "Low", "Medium", "hight"})
            For ct = 0 To t1.Count - 1 'Step' Each d In qt1.ToList
                Dim Tot = t1(ct).Value + t2(ct).Value + t3(ct).Value + t4(ct).Value + t5(ct).Value
                DataChart.Add({MyUI.Print.DateMonthDay(t1(ct).Trend_Date),
                   Utils.Math.Perc(t1(ct).Value, Tot),
                   Utils.Math.Perc(t2(ct).Value, Tot),
                   Utils.Math.Perc(t3(ct).Value, Tot),
                   Utils.Math.Perc(t4(ct).Value, Tot),
                   Utils.Math.Perc(t5(ct).Value, Tot)
                })
            Next

            Dim json = MyApp.JSONSerialize(New With {
                .data = DataChart
            })

            Me.AddJScript(SF("DrawChartStatus({0});", json))


        End If

    End Sub

    Private Sub SetDataEngagImpress()

        Dim t1 = CreateQueryTrend(mDB._Trend.Type.ENGAGEMENT_REL)
        Dim t2 = CreateQueryTrend(mDB._Trend.Type.IMPRESSION_REL)

        Me.LblEngagementCount.Text = UI.Print.Num0(t1.Sum(Function(o) o.Value))
        Me.LblEngagementAvg.Text = UI.Print.Num1(Utils.Math.Div(t1.Sum(Function(o) o.Value), t1.Count))

        Me.LblImpressionCount.Text = UI.Print.Num0(t2.Sum(Function(o) o.Value))
        Me.LblImpressionAvg.Text = UI.Print.Num1(Utils.Math.Div(t2.Sum(Function(o) o.Value), t2.Count))


        Me.UpPImpression.Update()

        '-------------------------------------
        'EXCEL

        If Excel IsNot Nothing Then
            Dim SheetTrend = Excel.GetExcelXmlSheet(3)
            SheetTrend.PasteData(3, "H", t1, {"value"})
            SheetTrend.PasteData(3, "I", t2, {"value"})
        End If

        '-------------------------------------
        ' CHART

        Dim DataChart As New List(Of Object())
        DataChart.Add({"data", "Message through"})
        For ct = 0 To t1.Count - 1 'Step' Each d In qt1.ToList
            DataChart.Add({MyUI.Print.DateMonthDay(t1(ct).Trend_Date), t1(ct).Value})
        Next

        Dim json = MyApp.JSONSerialize(New With {
            .data = DataChart
        })

        Dim DataChart2 As New List(Of Object())
        DataChart2.Add({"data", "Impression"})
        For ct = 0 To t2.Count - 1 'Step' Each d In qt1.ToList
            DataChart2.Add({MyUI.Print.DateMonthDay(t2(ct).Trend_Date), t2(ct).Value})
        Next

        Dim json2 = MyApp.JSONSerialize(New With {
            .data = DataChart2
        })

        Me.AddJScript(SF("DrawChartEngagImpress({0},{1});", json, json2))




    End Sub
    Private Sub SetDataAutoFollow()

        Dim t1 = CreateQueryTrend(mDB._Trend.Type.AUTO_FOLLOW_ACCOUNT)
        Dim t2 = CreateQueryTrend(mDB._Trend.Type.AUTO_FOLLOW_BECOME_FOLLOWER)
        Dim t3 = CreateQueryTrend(mDB._Trend.Type.AUTO_FOLLOW_NOT_FOLLOWER)

        Dim TotFoll = t2.Sum(Function(o) o.Value)
        Dim TotUnFoll = t3.Sum(Function(o) o.Value)
        Me.LblAutoFollAccount.Text = UI.Print.Num0(t1.Sum(Function(o) o.Value))
        Me.LblAutoFollBecFoll.Text = UI.Print.Num0(TotFoll) & " (" & UI.Print.Num0(Utils.Math.Perc(TotFoll, TotFoll + TotUnFoll)) & "%)"
        Me.LblAutoFollUnFoll.Text = UI.Print.Num0(TotUnFoll)



        Me.UpPChar4.Update()

        '-------------------------------------
        'EXCEL

        If Excel IsNot Nothing Then
            Dim SheetAutoFoll = Excel.GetExcelXmlSheet(6)
            SheetAutoFoll.PasteData(3, "A", t1, "Trend_Date", "value")
            SheetAutoFoll.PasteData(3, "C", t2, "value")
            SheetAutoFoll.PasteData(3, "D", t3, "value")
        End If

        '-------------------------------------
        ' CHART

        Dim DataChart As New List(Of Object())
        DataChart.Add({"data", "Follow", "Become follower", "Unfollower"})
        For ct = 0 To t1.Count - 1 'Step' Each d In qt1.ToList
            DataChart.Add({MyUI.Print.DateMonthDay(t1(ct).Trend_Date), t1(ct).Value, t2(ct).Value, t3(ct).Value})
        Next

        Dim json = MyApp.JSONSerialize(New With {
            .data = DataChart
        })

        Me.AddJScript(SF("DrawChartAutoFollow({0});", json))



    End Sub
    Private Sub SetDataActivity()

        If Not CurrAccount.Account_Auth.Analysis_Followers Then

            Me.AddJScript(SF("div_upgrade_plain('#{0} .wrapper');", Me.UpPCharActivity.ClientID))

        Else

            Dim classcount As Integer() = {0, 25, 250, 1000, 5000, 10000, 99999999}


            Dim t1 = CurrGroup.GetFollowerAnalysis(mDB.Follower_Analysis.Type.HOURS_ACTIVITY)
            Dim t2 = CurrGroup.GetFollowerAnalysis(mDB.Follower_Analysis.Type.FOLLOWERS_COUNT)

            '-------------------------------------
            ' EXCEL

            If Excel IsNot Nothing Then
                Dim SheetFoll = Excel.GetExcelXmlSheet(2)
                SheetFoll.PasteData(2, "A", t1, {"Data_Type_Id"})
                SheetFoll.PasteData(2, "B", t1, {"value"})
            End If

            '-------------------------------------
            ' CHAR

            Dim DataChart As New List(Of Object())
            DataChart.Add({"data", "value"})
            For ct = 0 To t1.Count - 1 'Step' Each d In qt1.ToList
                DataChart.Add({t1(ct).Data_Type_Id.ToString, t1(ct).Value})
            Next

            Dim json = MyApp.JSONSerialize(New With {
                .data = DataChart
            })

            Me.AddJScript(SF("DrawChartActivity({0});", json))


            '-------------------------------------
            ' CHAR

            DataChart = New List(Of Object())
            DataChart.Add({"data", "value", New With {.type = "string", .role = "tooltip"}})
            For ct = 0 To t2.Count - 1 'Step' Each d In qt1.ToList
                DataChart.Add({classcount(ct).ToString & " - " & classcount(ct + 1).ToString, t2(ct).Value, Utils.Math.Perc(t2(ct).Value, t2.Sum(Function(o) o.Value))})
            Next

            json = MyApp.JSONSerialize(New With {
                .data = DataChart
            })

            Me.AddJScript(SF("DrawChartFollowerCount({0});", json))


        End If

    End Sub
    Private Sub SetDataGender()

        Dim TotMales = CurrGroup.GetFollowerAnalysisValue(mDB.Follower_Analysis.Type.GENDER, mDB.Gender_Name.Type.MALE)
        Dim TotFemales = CurrGroup.GetFollowerAnalysisValue(mDB.Follower_Analysis.Type.GENDER, mDB.Gender_Name.Type.FEMALE)

        Me.LblMalePerc.Text = UI.Print.Num0(Utils.Math.Perc(TotMales, TotMales + TotFemales)) & "%"
        Me.LblFemalePerc.Text = UI.Print.Num0(Utils.Math.Perc(TotFemales, TotMales + TotFemales)) & "%"

        Dim TotBusiness = CurrGroup.GetFollowerAnalysisValue(mDB.Follower_Analysis.Type.BUSINESS, mDB.Account.BusinessType.BUSINESS)
        Dim TotPrivate = CurrGroup.GetFollowerAnalysisValue(mDB.Follower_Analysis.Type.BUSINESS, mDB.Account.BusinessType.PRIVATE)

        If Not CurrAccount.Account_Auth.Analysis_Followers Then
            Me.AddJScript(SF("div_upgrade_plain('#{0}');", "business_status"))
        Else
            Me.LblBusinessPerc.Text = UI.Print.Num0(Utils.Math.Perc(TotBusiness, TotBusiness + TotPrivate)) & "%"
        End If



        Me.UpPGender.Update()


        'excel
        If Excel IsNot Nothing Then
            Dim SheetFoll = Excel.GetExcelXmlSheet(2)
            SheetFoll.Cell(2, "E") = Utils.Math.Div(TotMales, TotMales + TotFemales)
            SheetFoll.Cell(3, "E") = Utils.Math.Div(TotFemales, TotMales + TotFemales)

            If CurrAccount.Account_Auth.Analysis_Followers Then
                SheetFoll.Cell(4, "E") = Utils.Math.Div(TotBusiness, TotBusiness + TotPrivate)
            End If

        End If

    End Sub
    Private Sub SetDataLanguage()


        Dim fas = CurrGroup.GetFollowerAnalysis(GloukDB.Follower_Analysis.Type.LANGUAGE)
        If fas.Count > 0 Then

            Dim Lang = DB.TAB.Language.Where("id", "in", fas.Select(Function(o) o.Data_Type_Id).ToList).ToList
            Dim dt1 =
                From fa In fas
                Join c In Lang On fa.Data_Type_Id Equals c.Id
                Select c.Lang_Code, fa.Value
                Order By Value Descending
                Take 4

            'Dim dt1 = CurrAccount.Tab_Follower_Analysis(mDB.Follower_Analysis.Type.LANGUAGE).
            '    Join("language", "id", "Follower_Analysis.data_type_id").
            '    SetSelect("language.lang_code", "Follower_Analysis.value").OrderBy("Follower_Analysis.value desc").Limit(4).
            'ToDataTable()

            'Utils.DT.ComputeData.Compute(dt1, "Perc", "{'value'} / {p0}", CurrAccount.Account_Update.Follower_Count)



            '-------------------------------------
            ' EXCEL
            If Excel IsNot Nothing Then
                Dim SheetFoll = Excel.GetExcelXmlSheet(2)
                SheetFoll.PasteData(2, "G", dt1, "lang_code", "value")
            End If


            '-------------------------------------
            ' CHAR

            Dim DataChart As New List(Of Object())
            DataChart.Add({"data", "value"})
            For ct = 0 To dt1.Count - 1 'Step' Each d In qt1.ToList
                DataChart.Add({dt1(ct).Lang_Code, dt1(ct).Value})
            Next

            Dim json = MyApp.JSONSerialize(New With {
                .data = DataChart
            })

            Me.AddJScript(SF("DrawChartLanguage({0});", json))

        End If

    End Sub

#End Region

    'Private Sub SetDataChar3()

    '    Dim s1 = CreateQueryTrend(CurrAccount.Id, mDB.Trend.Type.MESSAGE_REL).ToList
    '    Dim s2 = CreateQueryTrend(CurrAccount.Id, mDB.Trend.Type.SHARE_REL).ToList
    '    Dim s3 = CreateQueryTrend(CurrAccount.Id, mDB.Trend.Type.ENGAGEMENT_REL).ToList
    '    Dim s4 = CreateQueryTrend(CurrAccount.Id, mDB.Trend.Type.IMPRESSION_REL).ToList

    '    Dim minvalue = {s1.Count, s2.Count, s3.Count, s4.Count}.Min

    '    Dim xValues = s1.Select(Function(o) Format(o.Trend_Date, "MMM dd")).Take(minvalue).ToArray
    '    Dim yValues1 = s1.Select(Function(o) o.Value).Take(minvalue).ToArray
    '    Dim yValues2 = s2.Select(Function(o) o.Value).Take(minvalue).ToArray
    '    Dim yValues3 = s3.Select(Function(o) o.Value).Take(minvalue).ToArray
    '    Dim yValues4 = s4.Select(Function(o) o.Value).Take(minvalue).ToArray


    '    MyUI.Charts.SetGeoChart(Me.Chart2)


    '    With Me.Chart2


    '        With .ChartAreas("Area1")
    '            .AxisX.IsMarginVisible = False
    '            .AxisX.Interval = IntervalChart
    '            .AxisY.IsStartedFromZero = False
    '            .AxisY.LabelStyle.Format = UI.Print.FNum(0)
    '        End With

    '        .ChartAreas.Add(MyUI.Charts.DefautArea(2))
    '        MyUI.Charts.SetArea(.ChartAreas("Area2"))

    '        With .ChartAreas("Area2")
    '            .AxisX.Interval = IntervalChart
    '            .AxisX.IsMarginVisible = False
    '            .AxisY.IsStartedFromZero = False
    '            .AxisY.LabelStyle.Format = UI.Print.FNum(0)
    '        End With

    '        .ChartAreas.Add(MyUI.Charts.DefautArea(3))
    '        MyUI.Charts.SetArea(.ChartAreas("Area3"))

    '        With .ChartAreas("Area3")
    '            .AxisX.Interval = IntervalChart
    '            .AxisX.IsMarginVisible = False
    '            .AxisY.IsStartedFromZero = False
    '            .AxisY.LabelStyle.Format = UI.Print.FNum(0)
    '        End With

    '        .ChartAreas.Add(MyUI.Charts.DefautArea(4))
    '        MyUI.Charts.SetArea(.ChartAreas("Area4"))

    '        With .ChartAreas("Area4")
    '            .AxisX.Interval = IntervalChart
    '            .AxisX.IsMarginVisible = False
    '            .AxisY.IsStartedFromZero = False
    '            .AxisY.LabelStyle.Format = UI.Print.FNum(0)
    '        End With


    '        .Series.Add(MyUI.Charts.DefautSerie(1, DataVisualization.Charting.SeriesChartType.Spline))
    '        .Series.Add(MyUI.Charts.DefautSerie(2, DataVisualization.Charting.SeriesChartType.Spline))
    '        .Series.Add(MyUI.Charts.DefautSerie(3, DataVisualization.Charting.SeriesChartType.Spline))
    '        .Series.Add(MyUI.Charts.DefautSerie(4, DataVisualization.Charting.SeriesChartType.Spline))

    '        With .Series("Series1")
    '            .Points.DataBindXY(xValues, yValues1)
    '            .Color = Drawing.Color.Red
    '            .BorderWidth = 2
    '            .MarkerSize = 8
    '            .MarkerStyle = DataVisualization.Charting.MarkerStyle.Circle
    '            '.ToolTip = "#VALY"
    '            .LegendText = "Mention"
    '            .ChartArea = "Area1"
    '        End With

    '        With .Series("Series2")
    '            .Points.DataBindXY(xValues, yValues2)
    '            .BorderWidth = 2
    '            .MarkerSize = 8
    '            .MarkerStyle = DataVisualization.Charting.MarkerStyle.Diamond
    '            '.YAxisType = DataVisualization.Charting.AxisType.Secondary
    '            .LegendText = "Retweet"
    '            .ChartArea = "Area2"
    '        End With

    '        With .Series("Series3")
    '            .Points.DataBindXY(xValues, yValues3)
    '            .BorderWidth = 2
    '            .MarkerSize = 8
    '            .MarkerStyle = DataVisualization.Charting.MarkerStyle.Star5
    '            '.YAxisType = DataVisualization.Charting.AxisType.Secondary
    '            .LegendText = "Engagement"
    '            .ChartArea = "Area3"
    '        End With

    '        With .Series("Series4")
    '            .Points.DataBindXY(xValues, yValues4)
    '            .BorderWidth = 2
    '            .MarkerSize = 8
    '            .MarkerStyle = DataVisualization.Charting.MarkerStyle.Star5
    '            '.YAxisType = DataVisualization.Charting.AxisType.Secondary
    '            .LegendText = "Impression"
    '            .ChartArea = "Area4"
    '        End With

    '        .Legends.Add(MyUI.Charts.DefautLegend())

    '        Dim series As DataVisualization.Charting.Series
    '        For Each series In .Series
    '            Dim pointIndex As Integer
    '            For pointIndex = 0 To series.Points.Count - 1
    '                Dim toolTip As String = ""
    '                toolTip = series.Points(pointIndex).YValues(0)
    '                series.Points(pointIndex).MapAreaAttributes = "onmouseover=""DisplayTooltip('" + toolTip + "');"" onmouseout=""DisplayTooltip('');"""
    '                'series.Points(pointIndex).Url = "DetailedRegionChart.aspx?region=" + series.Points(pointIndex).AxisLabel
    '            Next pointIndex
    '            series.MapAreaAttributes = "onmouseover=""DisplayTooltip('ssss');"" onmouseout=""DisplayTooltip('');"""
    '        Next series


    '    End With




    'End Sub

#Region "CONSOLE"

    Private Sub SetDataConsole()

        'UI.Controls.ClassSet(Me.RbtDay15, "active", Me.ReportDay = 15)
        'UI.Controls.ClassSet(Me.RbtDay30, "active", Me.ReportDay = 30)
        'UI.Controls.ClassSet(Me.RbtDay60, "active", Me.ReportDay = 60)
        'UI.Controls.ClassSet(Me.RbtDay90, "active", Me.ReportDay = 90)

        'UI.Controls.ClassSet(Me.Rbtweekly, "active", Me.ReportGroup = "w")
        'UI.Controls.ClassSet(Me.RbtDaily, "active", Me.ReportGroup = "d")
        If Me.FromDate <> Date.MinValue Then
            Exit Sub
        End If

        If Date.TryParse(Me.TxtBeginDate.Text, Me.FromDate) And Date.TryParse(Me.TxtEndDate.Text, Me.ToDate) Then
            'Me.FromDate = Me.FromDate.AddDays(-1)
        Else


            Select Case GroupConsoleDay.SelectValue  'Me.ReportDay
                Case 15
                    Me.FromDate = Now.Date.AddDays(-15)
                Case 30
                    Me.FromDate = Now.Date.AddDays(-30)
                Case 60
                    Me.FromDate = Now.Date.AddDays(-60)
                Case 90
                    Me.FromDate = Now.Date.AddDays(-90)
            End Select

            Me.ToDate = Now.Date.AddDays(-1)

        End If

        Me.BtnExport.PostBackUrl = Request.Url.AbsoluteUri

        Me.LblReportDate.Text = SF("@{2}, from {0} to {1}", MyUI.Print.DateDayMonth(Me.FromDate), MyUI.Print.DateDayMonth(Me.ToDate), CurrAccount.Username)

        'excel
        If Excel IsNot Nothing Then
            Dim SheetData = Excel.GetExcelXmlSheet(1)
            SheetData.Cell(1, "B") = CurrAccount.Account_Add_Info.Post_Count
            SheetData.Cell(2, "B") = CurrAccount.Account_Add_Info.Friend_Count
            SheetData.Cell(3, "B") = CurrAccount.Account_Add_Info.Follower_Count

            SheetData.Cell(1, "D") = CurrAccount.Fullname
            SheetData.Cell(2, "D") = SF("@{0}", CurrAccount.Username)
            SheetData.Cell(3, "D") = CurrAccount.Description
            SheetData.Cell(4, "D") = CurrAccount.Location
            SheetData.Cell(5, "D") = CurrAccount.Url

            SheetData.Cell(2, "K") = Me.FromDate
            SheetData.Cell(3, "K") = Me.ToDate

        End If

    End Sub

    Protected Sub BtnUpdateData_Click(sender As Object, e As System.EventArgs) Handles BtnUpdateData.Click

        SetDataAnalysis()

    End Sub
    Protected Sub BtnExport_Click(sender As Object, e As System.EventArgs) Handles BtnExport.Click

        Dim PathTemplate = Server.MapPath("~/App/Export/")
        Dim FileTemplate = "DashBoard.xlsx"
        Dim UserFile = PathTemplate & FileTemplate & CurrAccount.Id

        IO.File.Copy(PathTemplate & FileTemplate, UserFile, True)

        Excel = New Export.Excel.ExcelXml
        Excel.OpenDoc(UserFile)

        SetDataAnalysis()

        'Dim ss2010 = ee2010.GetExcelXmlSheet(0)

        'ss2010.SetImage(58, "D", "http://a0.twimg.com/profile_images/3134702647/a94a7511fe0a42a5d0ca90bfe5f03b0c_normal.jpeg")


        Excel.Close()

        Response.AppendHeader("Content-Disposition", "attachment; filename=" & CurrAccount.Username & "_dashboard" & ".xlsx")
        Response.ContentType = "application/ms-excel"


        Response.WriteFile(UserFile)


        Response.End()




    End Sub


    Private Function CreateQueryTrend(t As mDB._Trend.Type) As List(Of mDB._Trend)

        Return CurrGroup.GetTrend(t, Me.FromDate, Me.ToDate, IIf(Me.GroupConsoleGroup.SelectValue = "w", DateInterval.Weekday, DateInterval.Day))

    End Function
    'Private Function CreateQueryTrend(t As mDB._Trend.Type) As List(Of mDB._Trend)


    '    Dim group = Me.ReportGroup = "w" ' Me.Rbtweekly.Checked

    '    Dim q = CurrAccount._Tab_Trend(t, Me.FromDate, Me.ToDate)

    '    If group Then
    '        q.
    '            GroupBy("YEARWEEK(trend_date)").
    '            SetSelect("trend_date", "sum(value) as value")
    '    Else
    '        q.
    '            SetSelect("trend_date", "value")

    '    End If


    '    Return q.ToList

    'End Function

    'Private Function CreateQueryTrend2(t As mDB._Trend.Type) As List(Of mDB._Trend)


    '    Dim group = Me.ReportGroup = "w" ' Me.Rbtweekly.Checked
    '    Dim accs = MyApp.GetCurrAccounts ' DB.TAB.Account.Where("id", "IN", New List(Of Integer) From {1, 209}).ToList
    '    Dim qs As New List(Of DBase.MySql.SqlQuery(Of mDB._Trend))
    '    Dim qfinal As New List(Of mDB._Trend)

    '    If accs.Count > 0 Then
    '        For Each acc In accs
    '            Dim q = acc._Tab_Trend(t, Me.FromDate, Me.ToDate)

    '            If group Then
    '                q.
    '                    GroupBy("YEARWEEK(trend_date)").
    '                    SetSelect("trend_date", "sum(value) as value")
    '            Else
    '                q.
    '                    SetSelect("trend_date", "value")

    '            End If

    '            qs.Add(q)

    '        Next

    '        qfinal = DB.GetQuery(Of mDB._Trend).
    '            From(DB.UnionQuery(qs), "tutto", "").
    '            GroupBy("trend_date").
    '            SetSelect("trend_date", "sum(value) as value").ToList
    '    End If



    '    Return qfinal

    'End Function
    'Private Function CreateQueryTrend3(t As mDB._Trend.Type) As List(Of mDB._Trend)


    '    Dim group = Me.ReportGroup = "w" ' Me.Rbtweekly.Checked
    '    Dim accs = MyApp.GetCurrAccounts 'Dim accs = DB.TAB.Account.Where("id", "IN", New List(Of Integer) From {1, 209}).ToList
    '    Dim dtfin = New List(Of mDB._Trend)


    '    For Each acc In accs
    '        Dim q = acc._Tab_Trend(t, Me.FromDate, Me.ToDate)

    '        If group Then
    '            q.
    '                GroupBy("YEARWEEK(trend_date)").
    '                SetSelect("trend_date", "sum(value) as value")
    '        Else
    '            q.
    '                SetSelect("trend_date", "value")

    '        End If

    '        dtfin.AddRange(q.ToList)

    '    Next


    '    dtfin = (
    '        From tr In dtfin
    '        Group tr By tr.Trend_Date Into g = Group
    '        Select New mDB._Trend With {.Trend_Date = Trend_Date, .Value = g.Sum(Function(o) o.Value)}
    '    ).ToList

    '    'Dim qfinal = DB.GetQuery(Of mDB._Trend).From(DB.UnionQuery(qs), "tutto", "").GroupBy("trend_date").SetSelect("trend_date", "sum(value) as value")

    '    Return dtfin

    'End Function


    Protected Sub GroupConsoleGroup_Selected(value As String) Handles GroupConsoleGroup.Selected
        SetDataPage()
    End Sub

    'Protected Sub RbtDay_CheckedChanged(sender As Object, e As System.EventArgs) _
    '    Handles Rbtweekly.Click, RbtDaily.Click

    '    Me.ReportGroup = sender.commandargument



    'End Sub
    'Protected Sub RbtDay15_Click(sender As Object, e As EventArgs) _
    '            Handles RbtDay15.Click, RbtDay30.Click, RbtDay60.Click, RbtDay90.Click

    '    Me.ReportDay = sender.commandargument

    '    Me.TxtBeginDate.Text = ""
    '    Me.TxtEndDate.Text = ""


    '    SetDataPage()


    'End Sub
    Protected Sub GroupConsoleDay_Selected(value As String) Handles GroupConsoleDay.Selected
        Me.TxtBeginDate.Text = ""
        Me.TxtEndDate.Text = ""


        SetDataPage()


    End Sub


#End Region


#Region "INTER ACCOUNT"

    'Private Sub SumInterAccount(dt As DataTable, Accs As Dictionary(Of Integer, Integer))

    '    For Each dr As DataRow In dt.Rows

    '        Dim Key = dr("account_id")

    '        If Accs.ContainsKey(Key) Then
    '            Accs(Key) += dr("total")
    '        Else
    '            Accs.Add(Key, dr("total"))
    '        End If

    '    Next

    'End Sub
    Protected Sub SetListInterractionAccount()
        Dim List = Me.ListUniqueInter

        Me.SetDataConsole()

        Dim InterAccs = CurrAccount.GetInterractionAccount(Me.FromDate, Me.ToDate.AddDays(1))

        If InterAccs.Count > 0 Then
            Dim Ids = (From a In InterAccs Order By a.Value Descending Select a.Key Take 100).ToList

            Dim DtAccs = DB.TAB.Account.
                REL.Account.Account_Add_Info.
                Where("id", "IN", Ids).
                OrderBy("FIELD(id," & String.Join(",", Ids) & ")").
                ToDataTable


            'Me.GridUsers.PageSize = 8

            If DtAccs.Rows.Count > 99 Then
                Me.LblUniqueInter.Text = "99+"
            Else
                Me.LblUniqueInter.Text = DtAccs.Rows.Count
            End If


            '-------------------------------------------------------
            ' LAYOUT
            '-------------------------------------------------------

            'Dim DataBind As List(Of Object) = UI.Grid.Bind(g, DtAccs, {})

            Dim DataBind As List(Of Object) = UI.ListData.Bind(List, DtAccs, {"ID"})

            MyUI.Data.SetListStatusAccount(CurrAccount, UI.ListData.GetRowsList(List), DataBind.Select(Function(o) o("account_code").ToString).ToList)

            '-------------------------------------------------------
            ' EXCEL
            '-------------------------------------------------------

            If Excel IsNot Nothing Then
                Dim SheetAccounts = Excel.GetExcelXmlSheet(5)
                SheetAccounts.PasteData(2, "A", DtAccs.DefaultView, "fullname", "username", "description", "location")

                Dim SheetDash = Excel.GetExcelXmlSheet(0)

                Dim r = 109
                For Each dr In DtAccs.Rows

                    SheetDash.SetImage(r, "I", dr("avatar"))
                    r += 2
                    If r > 117 Then Exit For
                Next

                'ExcelSheet0.PasteDataImage(58, "D", qAccs.Limit(5).ToDataTable, {"avatar"})
            End If


        Else
            UI.ListData.Bind(List, Nothing)
            Me.LblUniqueInter.Text = "0"
        End If


        Me.UpPUniqueInter.Update()



    End Sub
    Protected Sub ListUniqueInter_ItemCommand(sender As Object, e As ListViewCommandEventArgs) Handles ListUniqueInter.ItemCommand, ListNewFollUsers.ItemCommand
        Dim List As ListView = sender
        Dim Row = UI.ListDataItem.GetRow(e.CommandSource)

        If Row IsNot Nothing Then

            Dim id = UI.ListDataItem.GetKey(e.CommandSource)
            Dim Account = DB.TAB.Account.GetByPK(id)

            Dim tw = New MyApp.Network.Twitter(CurrAccount.GetOauth)

            Select Case e.CommandName
                Case "OPEN_PRIVATE"


                    Me.PrivateMessage.ToAccountId = Account.Id
                    Me.PrivateMessage.SetDataPage()
                    Me.Master.UpPPrivateMessage.Update()

                Case "FOLLOW"

                    tw.FollowAccont(CurrAccount, Account.Account_Code)
                    MyUI.Data.SetRowFriendAccount(Row, True)

                Case "UNFOLLOW"

                    tw.UnFollowAccont(CurrAccount, Account.Account_Code)
                    MyUI.Data.SetRowFriendAccount(Row, False)


            End Select

        End If


    End Sub

    'Protected Sub SetRowStatusAccount(g As GridView, AccountId As String, CommandName As String)

    '    For Each gr In g.Rows

    '        Dim butt = UI.GridRow.GetLinkButton(gr, "BtnFollow")
    '        Dim Lbl = UI.GridRow.GetLabel(gr, "LblFollower")

    '        If butt.CommandArgument = AccountId Then


    '            Select Case CommandName
    '                Case "FOLLOW"

    '                    UI.Controls.ClassReplace(butt, "a-icona1", "a-icona1-a")
    '                    butt.CommandName = "UNFOLLOW"

    '                Case "UNFOLLOW"

    '                    UI.Controls.ClassReplace(butt, "a-icona1-a", "a-icona1")
    '                    butt.CommandName = "FOLLOW"

    '                Case "FOLLOWER"
    '                    UI.Controls.ClassReplace(Lbl, "a-icona2", "a-icona2-a")


    '            End Select

    '        End If


    '    Next


    'End Sub
    'Protected Sub GridUsers_PageIndexChanging(sender As Object, e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridUsers.PageIndexChanging

    '    'Me.GridUsers.PageIndex = e.NewPageIndex

    '    Me.SetListInterractionAccount()

    'End Sub
    'Protected Sub GridUsers_RowCommand(sender As Object, e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridUsers.RowCommand
    '    Dim g As GridView = sender
    '    Dim gr = UI.GridRow.GetRow(e.CommandSource)

    '    If gr IsNot Nothing Then
    '        Dim BtnFollow = UI.GridRow.GetLinkButton(gr, "BtnFollow")
    '        Dim AccountCode = BtnFollow.CommandArgument
    '        Dim tc = New WebApi.Twitter.TwitterClient(CurrAccount.GetOauth)

    '        Select Case e.CommandName
    '            Case "FOLLOW"

    '                'tc.PostFriendshipsCreate("", AccountCode)
    '                CurrAccount.AddAccountLink(mDB.Account_Link.Type.FRIENDS, AccountCode, MyApp.Network.AccType.TWITTER_ACCOUNT)
    '                'SetRowStatusAccount(g, AccountCode, e.CommandName)
    '                'MyUI.Data.SetRowStatusAccount(UI.Grid.GetRowsList(g), AccountCode, e.CommandName)
    '                'MyUI.Data.SetListStatusAccount(CurrAccount, UI.Grid.GetRowsList(g))

    '            Case "UNFOLLOW"

    '                'tc.PostFriendshipsDestroy("", AccountCode)
    '                CurrAccount.RemoveAccountLink(mDB.Account_Link.Type.FRIENDS, AccountCode)
    '                'MyUI.Data.SetRowStatusAccount(UI.Grid.GetRowsList(g), AccountCode, e.CommandName)
    '                'SetRowStatusAccount(g, AccountCode, e.CommandName)
    '                'MyUI.Data.SetListStatusAccount(CurrAccount, UI.Grid.GetRowsList(g))

    '        End Select

    '    End If






    'End Sub


    'Protected Sub GridNewFollUsers_PageIndexChanging(sender As Object, e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridNewFollUsers.PageIndexChanging

    '    Me.GridNewFollUsers.PageIndex = e.NewPageIndex

    '    'SetDataChar()
    '    Me.SetDataConsole()
    '    Me.SetListNewFollowerAccount()

    'End Sub

#End Region

#Region "AUTO FOLLO"

    Protected Sub SetListNewFollowerAccount()
        Dim List = Me.ListNewFollUsers
        Dim dt As DataTable

        Me.SetDataConsole()


        dt = DB.TAB.Account.
            REL.Account.Account_Add_Info.
            REL.Account.Auto_Follow_Account_to_foll.
            BY.Auto_Follow_Account.Account_Id(Me.CurrAccount.Id, mDB.Auto_Follow_Account.StatusType.BECOME_FOLLOWER).
            Where("follow_date", ">", Me.FromDate, "follow_date", "<=", Me.ToDate.AddDays(1)).
            OrderBy("follow_date desc").
            Limit(100).
            Select("source_description as source").
        ToDataTable


        If dt.Rows.Count > 0 Then

            If dt.Rows.Count > 99 Then
                Me.LblUpPNewFoll.Text = "99+"
            Else
                Me.LblUpPNewFoll.Text = dt.Rows.Count
            End If

            '-------------------------------------------------------
            ' LAYOUT
            '-------------------------------------------------------

            Dim DataBind As List(Of Object) = UI.ListData.Bind(List, dt, {"account_id"})

            MyUI.Data.SetListStatusAccount(CurrAccount, UI.ListData.GetRowsList(List), DataBind.Select(Function(o) o("account_code").ToString).ToList)


        Else
            UI.ListData.Bind(List, Nothing)
            Me.LblUpPNewFoll.Text = "0"
        End If


        Me.UpPNewFoll.Update()

    End Sub
#End Region


#Region "SHARED POST"

    Protected Sub SetListSharePost()
        Dim List = Me.ListSharePosts

        Me.SetDataConsole()

        Dim dt As DataTable

        dt = CurrAccount.Tab_Share_Post.
            Where("pubb_date", ">", Me.FromDate).
            GroupBy("hash_id").
            OrderBy("share_count desc").Select("sum(share_det_count) as share_count, min(pubb_date) as pubb_date").
            Limit(101).
        ToDataTable()

        UI.ListData.Bind(List, dt)

        If dt.Rows.Count > 99 Then
            Me.LblSharePost.Text = "99+"
        Else
            Me.LblSharePost.Text = dt.Rows.Count
        End If

        Me.UpPSharePost.Update()

        'excel
        If Excel IsNot Nothing Then
            Dim SheetPosts = Excel.GetExcelXmlSheet(4)
            SheetPosts.PasteData(3, "A", dt.DefaultView, "pubb_date", "post_text", "share_count")
        End If
    End Sub
    'Protected Sub GridSharePosts_PageIndexChanging(sender As Object, e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridSharePosts.PageIndexChanging

    '    Me.GridSharePosts.PageIndex = e.NewPageIndex

    '    Me.SetDataConsole()
    '    Me.SetListSharePost()

    'End Sub

#End Region

    '#Region "MENTIONS"

    '    Private Sub SetListMessage()
    '        Dim dt As DataTable

    '        dt = DB.TAB.Account.
    '            REL.Account.Message_Post.
    '            BY.Message_Post.To_Account_Id(CurrAccount.Id).
    '            Where("pubb_date", ">", Me.FromDate).
    '            OrderBy("pubb_date desc").
    '            Limit(101).
    '        ToDataTable()

    '        Me.GridMessage.PageSize = 5
    '        UI.Grid.Bind(Me.GridMessage, dt)

    '        If dt.Rows.Count > 99 Then
    '            Me.LblMessage.Text = "99+"
    '        Else
    '            Me.LblMessage.Text = dt.Rows.Count
    '        End If

    '        Me.UpPMessage.Update()

    '    End Sub
    '    Protected Sub GridMessage_PageIndexChanging(sender As Object, e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridMessage.PageIndexChanging

    '        Me.GridMessage.PageIndex = e.NewPageIndex

    '        Me.SetDateChar()
    '        Me.SetListMessage()

    '    End Sub
    '    Protected Sub GridMessage_RowCommand(sender As Object, e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridMessage.RowCommand
    '        Dim g As GridView = sender
    '        Dim gr = UI.GridRow.GetRow(e.CommandSource)

    '        If gr IsNot Nothing Then

    '            Dim butt = UI.GridRow.GetLinkButton(gr, "LBtShare")
    '            Dim tc = New WebApi.Twitter.TwitterClient(CurrAccount.getOauth)

    '            Select Case e.CommandName
    '                Case "SHARE"


    '                    Dim post As Object = Nothing
    '                    Try

    '                        post = tc.PostReTweet(butt.CommandArgument)

    '                    Catch ex As WebApi.Net.ExceptionRequest

    '                    End Try

    '                    If post Is Nothing Then
    '                        butt.Text = "ERROR"
    '                    Else
    '                        butt.Text = "SHARED"
    '                    End If

    '            End Select
    '        End If






    '    End Sub


    '#End Region


End Class



